/*
 * @file    count_word.cpp
 * @author  libo <libo@tencent.com>
 * @date    2013-03-22
 * @brief   
 * */

#include <iostream>

int count_word(char* str) {
    int count = 0;
    bool in_word = false;
    while(*str) {
        if(!in_word && isalpha(*str)) {
            ++count;
            in_word = true;
        } else if(in_word && *str == ' ') {
            in_word = false;
        }
        str++;
    }
    return count;
}

int main() {
    char tmp[100];
    strcpy(tmp, "    hello world     baby   ");
    std::cout << count_word(tmp);
}
